package com.koron.ticket.work.workmember.service;

import com.koron.common.core.util.CodeTools;
import com.koron.ticket.work.workmember.bean.WorkMember;
import com.koron.ticket.work.workmember.bean.WorkMemberQuery;
import com.koron.ticket.work.workmember.mapper.WorkMemberMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkMemberService {
    public void insert(SessionFactory factory, WorkMember workMember) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        workMemberMapper.insert(workMember);
    }

    public void batchInsertOnTicketId(SessionFactory factory, List<WorkMember> list, String ticketId) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        list.stream().forEach(l->{
            l.setId(CodeTools.getCode32());
            l.setWorkTicketId(ticketId);
            l.setDeleteFlag(0);
        });
        workMemberMapper.batchInsert(list);
    }

    public void batchInsert(SessionFactory factory, List<WorkMember> list) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        workMemberMapper.batchInsert(list);
    }

    public void deleteByWorkTicketId(SessionFactory factory, String workTicketId) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        workMemberMapper.deleteByWorkTicketId(workTicketId);
    }

    public List<WorkMember> getList(SessionFactory factory, WorkMemberQuery workMemberQuery) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        List<WorkMember> workMemberList = workMemberMapper.getList(workMemberQuery);
        return workMemberList;
    }

    public List<WorkMember> queryByWorkTicketId(SessionFactory factory, String workTicketId) {
        WorkMemberMapper workMemberMapper = factory.getMapper(WorkMemberMapper.class);
        List<WorkMember> workMembers = workMemberMapper.queryByWorkTicketId(workTicketId);
        return workMembers;
    }


}
